/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  com.alibaba.fastjson.JSON
 *  com.alibaba.fastjson.JSONObject
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.stereotype.Service
 *  org.springframework.transaction.annotation.Transactional
 *  tk.mybatis.mapper.entity.Example
 */
package com.gys.spliteService.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gys.common.business.SyncUtil;
import com.gys.common.data.HttpJson;
import com.gys.mapper.GaiaProductBasicMapper;
import com.gys.mapper.GaiaProductBusinessMapper;
import com.gys.mapper.GaiaSdEmpGroupMapper;
import com.gys.mapper.GaiaSdProductPriceMapper;
import com.gys.mapper.GaiaSdProuctLocationMapper;
import com.gys.mapper.GaiaSdSaleDMapper;
import com.gys.mapper.GaiaSdSaleHMapper;
import com.gys.mapper.GaiaSdStockBatchMapper;
import com.gys.mapper.GaiaSdStockMapper;
import com.gys.mapper.GaiaSdStoreDataMapper;
import com.gys.mapper.GaiaStoreDataMapper;
import com.gys.mapper.GaiaUserDataMapper;
import com.gys.mapper.entity.GaiaProductBusiness;
import com.gys.mapper.entity.GaiaSdEmpGroup;
import com.gys.mapper.entity.GaiaSdProductPrice;
import com.gys.mapper.entity.GaiaSdProuctLocation;
import com.gys.mapper.entity.GaiaSdSaleD;
import com.gys.mapper.entity.GaiaSdSaleH;
import com.gys.mapper.entity.GaiaSdStock;
import com.gys.mapper.entity.GaiaSdStockBatch;
import com.gys.mapper.entity.GaiaSdStoreData;
import com.gys.mapper.entity.GaiaStoreData;
import com.gys.mapper.entity.GaiaUserData;
import com.gys.spliteService.SyncService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

@Service
public class SyncServiceImpl
implements SyncService {
    private static final Logger log = LoggerFactory.getLogger(SyncServiceImpl.class);
    @Autowired
    private GaiaUserDataMapper userDataMapper;
    @Autowired
    private GaiaStoreDataMapper storeDataMapper;
    @Autowired
    private GaiaProductBasicMapper productBasicMapper;
    @Autowired
    private GaiaProductBusinessMapper productBusinessMapper;
    @Autowired
    private GaiaSdProductPriceMapper sdProductPriceMapper;
    @Autowired
    private GaiaSdProuctLocationMapper sdProuctLocationMapper;
    @Autowired
    private GaiaSdStockMapper sdStockMapper;
    @Autowired
    private GaiaSdStockBatchMapper sdStockBatchMapper;
    @Autowired
    private GaiaSdStoreDataMapper sdStoreDataMapper;
    @Autowired
    private GaiaSdEmpGroupMapper sdEmpGroupMapper;
    @Autowired
    private GaiaSdSaleHMapper sdSaleHMapper;
    @Autowired
    private GaiaSdSaleDMapper sdSaleDMapper;

    @Override
    @Transactional
    public void syncUserData() {
        HttpJson rsp = SyncUtil.selectBaseInfo();
        if (rsp.isSuccess()) {
            JSONObject jsonObject = JSON.parseObject((String)rsp.getMsg());
            List<GaiaUserData> userList = JSON.parseArray((String)jsonObject.getString("userList"), GaiaUserData.class);
            Example example = new Example(GaiaUserData.class);
            this.userDataMapper.deleteByExample(example);
            for (GaiaUserData user : userList) {
                this.userDataMapper.insert(user);
            }
            List<GaiaStoreData> storeList = JSON.parseArray((String)jsonObject.getString("storeList"), GaiaStoreData.class);
            example = new Example(GaiaStoreData.class);
            this.storeDataMapper.deleteByExample(example);
            for (GaiaStoreData store : storeList) {
                this.storeDataMapper.insert(store);
            }
            log.info("\u540c\u6b65\u57fa\u672c\u4fe1\u606f\u6210\u529f");
        } else {
            log.info("\u540c\u6b65\u57fa\u672c\u4fe1\u606f\u5931\u8d25" + rsp.getMsg());
        }
    }

    @Override
    @Transactional
    public void syncProductData() {
        HttpJson rsp = SyncUtil.selectProductInfo();
        if (rsp.isSuccess()) {
            JSONObject jsonObject = JSON.parseObject((String)rsp.getMsg());
            List<GaiaProductBusiness> productBusinessList = JSON.parseArray((String)jsonObject.getString("productBusinessList"), GaiaProductBusiness.class);
            Example example = new Example(GaiaProductBusiness.class);
            this.productBusinessMapper.deleteByExample(example);
            for (GaiaProductBusiness business : productBusinessList) {
                this.productBusinessMapper.insert(business);
            }
            List<GaiaSdProductPrice> productPriceList = JSON.parseArray((String)jsonObject.getString("productPriceList"), GaiaSdProductPrice.class);
            example = new Example(GaiaSdProductPrice.class);
            this.sdProductPriceMapper.deleteByExample(example);
            for (GaiaSdProductPrice price : productPriceList) {
                this.sdProductPriceMapper.insert(price);
            }
            List<GaiaSdProuctLocation> productLocationList = JSON.parseArray((String)jsonObject.getString("productLocationList"), GaiaSdProuctLocation.class);
            example = new Example(GaiaSdProuctLocation.class);
            this.sdProuctLocationMapper.deleteByExample(example);
            for (GaiaSdProuctLocation location : productLocationList) {
                this.sdProuctLocationMapper.insert(location);
            }
            log.info("\u540c\u6b65\u5546\u54c1\u4fe1\u606f\u6210\u529f");
        } else {
            log.info("\u540c\u6b65\u5546\u54c1\u4fe1\u606f\u5931\u8d25" + rsp.getMsg());
        }
    }

    @Override
    @Transactional
    public void syncStoreData() {
        HttpJson rsp = SyncUtil.selectStoreInfo();
        if (rsp.isSuccess()) {
            JSONObject jsonObject = JSON.parseObject((String)rsp.getMsg());
            List<GaiaSdStock> sdStockList = JSON.parseArray((String)jsonObject.getString("sdStockList"), GaiaSdStock.class);
            Example example = new Example(GaiaSdStock.class);
            this.sdStockMapper.deleteByExample(example);
            for (GaiaSdStock stock : sdStockList) {
                this.sdStockMapper.insert(stock);
            }
            List<GaiaSdStockBatch> sdStockBatchList = JSON.parseArray((String)jsonObject.getString("sdStockBatchList"), GaiaSdStockBatch.class);
            example = new Example(GaiaSdStockBatch.class);
            this.sdStockBatchMapper.deleteByExample(example);
            for (GaiaSdStockBatch stockBatch : sdStockBatchList) {
                this.sdStockBatchMapper.insert(stockBatch);
            }
            List<GaiaSdStoreData> sdStoreList = JSON.parseArray((String)jsonObject.getString("sdStoreList"), GaiaSdStoreData.class);
            example = new Example(GaiaSdStoreData.class);
            this.sdStoreDataMapper.deleteByExample(example);
            for (GaiaSdStoreData storeData : sdStoreList) {
                this.sdStoreDataMapper.insert(storeData);
            }
            List<GaiaSdEmpGroup> sdEmpGroupList = JSON.parseArray((String)jsonObject.getString("sdEmpGroupList"), GaiaSdEmpGroup.class);
            example = new Example(GaiaSdEmpGroup.class);
            this.sdEmpGroupMapper.deleteByExample(example);
            for (GaiaSdEmpGroup empGroup : sdEmpGroupList) {
                this.sdEmpGroupMapper.insert(empGroup);
            }
            log.info("\u540c\u6b65\u95e8\u5e97\u6210\u529f");
        } else {
            log.info("\u540c\u6b65\u95e8\u5e97\u5931\u8d25" + rsp.getMsg());
        }
    }

    @Override
    @Transactional
    public void syncSaleData() {
        HttpJson rsp = SyncUtil.selectSaleInfo();
        if (rsp.isSuccess()) {
            this.sdSaleDMapper.deleteUpload();
            this.sdSaleHMapper.deleteUpload();
            JSONObject jsonObject = JSON.parseObject((String)rsp.getMsg());
            List<GaiaSdSaleH> sdSaleHList = JSON.parseArray((String)jsonObject.getString("sdSaleHList"), GaiaSdSaleH.class);
            for (GaiaSdSaleH sdSaleH : sdSaleHList) {
                sdSaleH.setGsshUpload("1");
                this.sdSaleHMapper.insert(sdSaleH);
            }
            List<GaiaSdSaleD> sdSaleDList = JSON.parseArray((String)jsonObject.getString("sdSaleDList"), GaiaSdSaleD.class);
            for (GaiaSdSaleD sdSaleD : sdSaleDList) {
                this.sdSaleDMapper.insert(sdSaleD);
            }
            log.info("\u540c\u6b65\u9500\u552e\u5355\u6210\u529f");
        } else {
            log.info("\u540c\u6b65\u9500\u552e\u5355\u5931\u8d25" + rsp.getMsg());
        }
    }
}

